using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

namespace Portal
{
	/// <summary>
	/// Summary description for EditModuleTable.
	/// </summary>
	public partial class EditModuleTable : System.Web.UI.Page
	{
		protected System.Web.UI.HtmlControls.HtmlTableCell tdEdit;

		protected void Page_Load(object sender, System.EventArgs e)
		{
			cssLink.Href = Portal.Helper.CssAdminPath;
			if (!IsPostBack)
			{
				ModuleEditCtrl.LoadData(Request["TabRef"], Request["ModuleRef"]);
				phHeader.Controls.Add(LoadControlPara("PortalHeader.ascx", "AdminHeader.htm"));
			}
		}

		protected void OnSave(object sender, System.EventArgs args)
		{
			Response.Redirect(Portal.API.AppConfig.GetTabUrl(Request["TabRef"]));
		}
		protected void OnCancel(object sender, System.EventArgs args)
		{
			Response.Redirect(Portal.API.AppConfig.GetTabUrl(Request["TabRef"]));
		}
		protected void OnDelete(object sender, System.EventArgs args)
		{
			Response.Redirect(Portal.API.AppConfig.GetTabUrl(Request["TabRef"]));
		}
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{

		}
		#endregion

		private UserControl LoadControlPara(string UserControlPath, params object[] constructorParameters)
		{
			List<Type> constParamTypes = new List<Type>();
			foreach (object constParam in constructorParameters)
			{
				constParamTypes.Add(constParam.GetType());
			}

			UserControl ctl = Page.LoadControl(UserControlPath) as UserControl;

			// Find the relevant constructor
			System.Reflection.ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());

			//And then call the relevant constructor
			if (constructor == null)
			{
				throw new MemberAccessException("The requested constructor was not found on : " + ctl.GetType().BaseType.ToString());
			}
			else
			{
				constructor.Invoke(ctl, constructorParameters);
			}

			// Finally return the fully initialized UC
			return ctl;
		}


	}
}
